package com.lsp.lib_uikit.commonrecycler.defaultview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.TextView;
import com.lsp.lib_uikit.R;

/**
 * 默认的加载footer
 *
 * @author lsp
 * @created 16/10/13 10:21
 */
public class DefaultFooterView extends LoadingMoreFooterBase {

  private TextView mTextView;
  private Context mContext;

  public DefaultFooterView(Context context) {
    this(context, null);
  }

  public DefaultFooterView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public DefaultFooterView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mContext = context;
    setUpViews();
  }

  private void setUpViews() {
    LayoutInflater.from(getContext()).inflate(R.layout.commonrecycler_load_more_default, this);
    mTextView = (TextView) findViewById(R.id.tv_load_more_default);
  }

  @Override public void onLoadError() {
    //setVisibility(GONE);
    ////mTextView.setText("点击加载更多");
    //Toast.makeText(mContext, "加载失败，请重试", Toast.LENGTH_SHORT).show();
    setVisibility(VISIBLE);
    mTextView.setText("加载失败，请重试");
    //Toast.makeText(mContext, "加载失败，请重试", Toast.LENGTH_SHORT).show();
  }

  @Override public void onLoadLoading() {
    setVisibility(VISIBLE);
    mTextView.setText("加载中...");
  }

  @Override public void onLoadFinish(boolean hasMore) {
    if (!hasMore) {
      setVisibility(VISIBLE);
      mTextView.setText("没有更多了");
    } else {
      setVisibility(GONE);
    }
  }

  @Override public void onWaitToLoadMore() {
    setVisibility(VISIBLE);
    mTextView.setText("点击加载更多");
  }
}
